/*
 * @Description:londing 加载场景
 * @Author: maskMan
 * @LastEditTime: 2024-10-17 19:05:27
 */
import CacheStore from '../general/cacheStore'
import Config from '../general/config'
import { STATUS } from '../general/constants'
import ResManager from '../general/resManager'
const { ccclass, property } = cc._decorator
@ccclass
export class loading extends cc.Component {
  @property(cc.Label)
  tips: cc.Label = null
  @property(cc.Label)
  title: cc.Label = null
  @property(cc.Label)
  ver: cc.Label = null
  @property(cc.Label)
  percentNum: cc.Label = null
  loadSceneName = 'hall'
  onLoad() {
    // CacheStore.clearData()
    /**设置横屏 */
    cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT)
    this._init()
  }
  /**初始化设置 */
  private _init() {
    this._loadConfig()
    this._loadingDir()
  }
  /**初始化加载 */
  private _loadingDir() {
    var self = this
    self.tips.string = '加载中...'
    var onProgress = function (completedCount: number, totalCount: number) {
      const pressNum = Math.floor((completedCount / totalCount) * 100)
      self.percentNum.string = pressNum.toString()
    }
    var onFinished = function (err) {
      if (!err) {
        self.percentNum.node.active = false
        cc.director.loadScene('hall')
        return
      }
      self.tips.string = err
    }
    ResManager.loadingDir('/', onProgress, onFinished)
  }
  /**加载设置 */
  private _loadConfig() {
    Config.status = CacheStore.getConfigData('status') || STATUS.TEST
    this.ver.string = Config.ver
    if (Config.status == STATUS.TEST) {
      this.title.node.active = true
    } else {
      this.title.node.active = false
    }
  }
}
